from django.urls import path
from django.http import HttpResponse
from . import views
from .agent_runner_views import AgentRunnerView

urlpatterns = [
    # 智能体运行路由
    path('agent-runner/', AgentRunnerView.as_view(), name='agent_runner'),
    path('agent/run/<int:agent_id>/', AgentRunnerView.as_view(), name='agent_run'),
    # 智能体管理路由
    path('agent-management/', views.agent_management, name='agent_management'),
    path('agent-management/create/', views.agent_create, name='agent_create'),
    path('agent-management/<int:pk>/config/', views.agent_config, name='agent_config'),
    path('agent-management/form/', views.agent_form, name='agent_form'),
    path('agent-management/<int:pk>/form/', views.agent_form, name='agent_form'),
    # 数据源管理路由
    path('', views.DataSourceListView.as_view(), name='datasource_list'),
    path('create/', views.DataSourceCreateView.as_view(), name='datasource_create'),
    path('<int:pk>/edit/', views.DataSourceUpdateView.as_view(), name='datasource_edit'),
    path('<int:pk>/config/', views.datasource_config, name='datasource_config'),
    path('<int:pk>/delete/', views.DataSourceDeleteView.as_view(), name='datasource_delete'),
    path('sql-config/<int:pk>/view/', views.sql_config_view, name='sql_config_view'),
    # 获取数据源配置json
    path('api/datasource/<int:pk>/config/', views.get_datasource_config, name='get_datasource_config'),
    # API路由
    path('api/datasource/<int:pk>/tables/', views.get_table_fields, name='get_table_fields'),
    # SQL配置API路由
    path('api/datasource/<int:pk>/sql-configs/', views.get_sql_configs, name='get_sql_configs'),
    path('api/sql-config/<int:pk>/', views.get_sql_config, name='get_sql_config'),
    path('api/sql-config/create/', views.create_sql_config, name='create_sql_config'),
    path('api/sql-config/<int:pk>/update/', views.update_sql_config, name='update_sql_config'),
    path('api/sql-config/<int:pk>/delete/', views.delete_sql_config, name='delete_sql_config'),
    # 获取表字段信息用于SQL配置
    path('api/datasource/<int:pk>/table/<str:table_name>/fields/', views.get_table_fields_for_sql_config, name='get_table_fields_for_sql_config'),
    # 原有路由（如有需要保留）
    path('test-connection/', views.TestConnectionView.as_view(), name='test_connection'),
    path('save-config/', views.SaveConfigView.as_view(), name='save_config'),
    path('operation-log/', lambda request: HttpResponse("暂未实现"), name='operation_log'),
    # 智能体指令API路由
    path('api/agent/instruct/', views.AgentInstructionView.as_view(), name='agent-instruct'),
]
